define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/withdraw_money/index',
                    // add_url: 'finance/withdraw_money/add',
                    // edit_url: 'finance/withdraw_money/edit',
                    // del_url: 'finance/withdraw_money/del',
                    // multi_url: 'finance/withdraw_money/multi',
                    table: 'withdraw_money',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName:'id',
                sortOrder:'desc',
                commonSearch: true,
                strictSearch: true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'name', title: __('Name'), operate:'like'},
                        {field: 'username', title: __('Username'), operate:'like'},
                        {field: 'money', title: __('Money'), operate:'like'},
                        {field: 'type', title: __('Type'), formatter: Table.api.formatter.status, searchList: {1: __('支付宝'), 2: __('银行卡')}},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {to_examine: __('待审核'), normal: __('已审核'),reject:__('已驳回')}},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('通过'),
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'finance/withdraw_money/to_examine',
                                    confirm: '确认通过审核吗?',
                                    visible: function (row) {
                                        if (row.status == 'to_examine') {
                                            return true;
                                        }
                                        return false;
                                    },
                                    success: function () {
                                        $(".btn-refresh").trigger("click");//提交后刷新当前页面，你会需要这个的！
                                    }
                                },
                                {
                                    name: 'ajax',
                                    text: __('驳回'),
                                    title: __('驳回'),
                                    classname: 'btn btn-xs btn-primary btn-magic btn-ajax',
                                    url: 'finance/withdraw_money/reject',
                                    confirm: '确认驳回审核吗?',
                                    visible: function (row) {
                                        if (row.status == 'to_examine') {
                                            return true;
                                        }
                                        return false;
                                    },
                                    success: function () {
                                        $(".btn-refresh").trigger("click");//提交后刷新当前页面，你会需要这个的！
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});